{% extends "base.html" %}
{% block head %}
{{ super() }}
<link rel="stylesheet" href="{{ url_for('static', filename='css/bootstrap-datetimepicker.min.css') }}">
<link rel="stylesheet" href="{{ url_for('static', filename='css/select2.min.css') }}">
{% endblock %}
{% block content %}
<div class="container-fluid">
    <div class="row">
   	 <div class="col-sm-3 col-md-2 sidebar">
	     <ul class="nav nav-sidebar">
	
		{% if session['role'] not in ['service'] %}
		<li id="nav_assign">
		    <a href="{{ url_for('assign.assign_list')  }}">申请分配</a>
		</li> 
		{% endif %}
		<li id="nav_track">
		    <a href="#TrackMenu" data-toggle="collapse">申请跟进</a>
		    <ul id="TrackMenu" class="nav nav-list collapse col-md-offset-1">  
                        <li id="li_buy" ><a href="{{ url_for('track.buy_list') }}">购车申请</a></li>  
                        <li id="li_rent" ><a href="{{ url_for('track.business_list', btype='rent') }}">租赁申请</a></li>  
                        <li id="li_finance" ><a href="{{ url_for('track.business_list', btype='finance') }}">金融申请</a></li>
                        <li id="li_service" ><a href="{{ url_for('track.business_list', btype='service') }}">服务申请</a></li>  
                    </ul>
                </li>
		<li id="nav_advice">
		    <a href="{{ url_for('advice.advice_list')  }}">投诉/建议</a>
		</li> 
	     </ul>
	 </div>
	 <div class="col-sm-9 col-sm-offset-3 col-md-10 col-md-offset-2 main">
   	 	{% for message in get_flashed_messages() %}
		<div class="alert alert-warning">
        		<button type="button" class="close" data-dismiss="alert">&times;</button>
	        	{{ message }}	
		 </div>
		{% endfor %}
		
		{% block page_content %}
		<h1 class="page-header">{{ title }}</h1>
		<div class="col-md-12">
			<div class="col-md-1" style="margin-top:3px;">
				<select class="select2" id="search_type" >
					<option value='5'>选择条件</option>
					<option value='0'>按ID</option>
					<option value='1'>按提交人</option>
					<option value='2'>按地区</option>
					<option value='3'>按时间</option>
					<option value='4'>联合搜索</option>
				</select>
			</div>
			<div id="by_id" class="col-md-2" style="display:none;">
				<input id="number" style="height:36px;width:95%;margin-left:20px;"type="text" placeholder="输入完整ID">
			</div>
			<div id="by_time" class="col-md-4" style="display:none;" >
				<div class="col-md-5">
					<input type="text" id="start" style="height:36px;width:98%;" readonly required>
				</div>
				<div class="col-md-1" style="margin-right:15px;margin-top:8px;font-size:15px;">至</center></div>
				<div class="col-md-5">
					<input type="text" id="end" style="height:36px;width:98%;" readonly required>
				</div>
			</div>
			<div id="by_area" class="col-md-2" style="display:none;" >
				<input id="area" style="height:36px;width:100%;"type="text" placeholder="地区">
			</div>
			<div id="by_sbm" class="col-md-2" style="display:none;margin-top:3px;" >
				<center>
					<select class="select2" id="submitter" >
						<option value='0'>个人用户</option>
						<option value='1'>商家用户</option>
					</select>
				</center>
			</div>
			<div id="buttons" class="col-md-2" style="display:none;" >
				<button class="btn btn-info" onclick="search()" >&nbsp查询&nbsp</button>
				<button class="btn btn-warning" onclick="reset()" >&nbsp重置&nbsp</button>
			</div>
			<input id="tb_name" type="hidden">
		</div>

		{% endblock %}
	 </div>
    </div>
</div>
{% endblock %}
{% block scripts %}
{{ super() }}
<script src="{{ url_for('static', filename='js/bootstrap-datetimepicker.min.js') }}"></script>
<script src="{{ url_for('static', filename='js/bootstrap-datetimepicker.zh-CN.js') }}" charset="UTF-8"></script>
<script src="{{ url_for('static', filename='js/select2.min.js') }}"></script>
<script>

var by_id = document.getElementById('by_id');
var by_sbm = document.getElementById('by_sbm');
var by_area = document.getElementById('by_area');
var by_time = document.getElementById('by_time');
var by_combine = document.getElementById('combine');
var buttons = document.getElementById('buttons');

var GetToday = function(){

	var today = new Date();
	var month = today.getMonth() + 1;
	month = month < 10 ? '0' + month : month;
	var day = today.getDate();
	day = day < 10 ? '0' + day : day;
	var value = today.getFullYear() + '-' + month + '-' + day ;
	return value;
}

$(document).ready(function(){
	
  	$(".select2").select2({
		minimumResultsForSearch: Infinity,
	});

	var value = GetToday();

	$('#start').datetimepicker({
		format: 'yyyy-mm-dd',
		language: 'zh-CN',
		autoclose: true,
		minView: 2,
	});
	
	$('#end').datetimepicker({
		format: 'yyyy-mm-dd',
		language: 'zh-CN',
		autoclose: true,
		minView: 2,
	});

	$('#start').datetimepicker('setEndDate', value);
	$('#end').datetimepicker('setEndDate', value);

	document.getElementById('start').value = value;
	document.getElementById('end').value = value;

	$('#search_type').on('select2:selecting', function(e){
		var value = e.params.args.data.id;
		if(value==='5'){
			by_id.style.display = 'none';
			by_sbm.style.display = 'none';
			by_area.style.display = 'none';
			by_time.style.display = 'none';
			buttons.style.display = 'none';
		}
		else if(value==='4'){
			by_id.style.display = 'none';
			by_sbm.style.display = '';
			by_area.style.display = '';
			by_time.style.display = '';
			buttons.style.display = '';
		}
		else{
			by_id.style.display = 'none';
			by_sbm.style.display = 'none';
			by_area.style.display = 'none';
			by_time.style.display = 'none';
			buttons.style.display = '';
			if(value==='0'){
				by_id.style.display = '';
			}
			else if(value==='1'){
				by_sbm.style.display = '';
			}
			else if(value==='2'){
				by_area.style.display = '';
			}
			else if(value==='3'){
				by_time.style.display = '';
			}
		}
	})
	$('#search_type').select2('val', '5');
});

var reset = function(){

	$('#search_type').select2('val', '5');
	by_id.style.display = 'none';
	by_sbm.style.display = 'none';
	by_area.style.display = 'none';
	by_time.style.display = 'none';
	buttons.style.display = 'none';
	search();
}

</script>
{% endblock %}
